package com.downhometech.productcalculator.models;

import java.io.Serializable;

public class CartItem implements Serializable
{
	private Product product = null;
	private double quantity = 0;
	private double discount = 0;
	private boolean discountAPercentage = false;
	private boolean listPriceUsed = false;
	
	


	public boolean isListPriceUsed() {
		return listPriceUsed;
	}

	public void setListPriceUsed(boolean listPriceUsed) {
		this.listPriceUsed = listPriceUsed;
	}

	public CartItem(Product product, double quantity, double discount, boolean isDiscountAPercentage, boolean isListPriceUsed) {
		super();
		this.product = product;
		this.quantity = quantity;
		this.discount = discount;
		this.discountAPercentage=isDiscountAPercentage;
		this.listPriceUsed=isListPriceUsed;
	}
	
	public CartItem() { }
	
	public Product getProduct() {
		return product;
	}
	public void setProduct(Product product) {
		this.product = product;
	}
	public double getQuantity() {
		return quantity;
	}
	public void setQuantity(double quantity) {
		this.quantity = quantity;
	}
	public double getDiscount() {
		return discount;
	}
	public void setDiscount(double discount) {
		this.discount = discount;
	}
	public double getDiscountCalculated() {
		Product product = getProduct();
		if (isDiscountAPercentage() && this.discount > 1) {	return (getProductPrice()  * (this.discount / 100)); }
		else if (isDiscountAPercentage()) { return  (getProductPrice() * this.discount); }
		else {  return this.discount; }
	}
	
	private double getProductPrice()
	{
		if (isListPriceUsed()) { return getProduct().getListedPrice(); }
		else { return getProduct().getCustomPrice(); }
	}
	
	
	public double getTotalPrice() {
		return (getQuantity() * getProductPrice()) - getDiscountCalculated();

	}
	
	public double getTotalPriceWithOutDiscount() {
		return getQuantity() * (getProductPrice());
	}


	public boolean isDiscountAPercentage() {
		return discountAPercentage;
	}

	public void setDiscountAPercentage(boolean discountAPercentage) {
		this.discountAPercentage = discountAPercentage;
	}
	
}
